package com.luokangtao.user.controller;

import com.luokangtao.common.entity.PageResult;
import com.luokangtao.common.entity.Result;
import com.luokangtao.user.dto.UserQueryCondition;
import com.luokangtao.user.entity.User;
import com.luokangtao.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author luokangtao
 * @create 2019-07-22 20:33
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(value = "用户接口",tags = "用户接口大全")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ApiOperation("根据id查询用户")
    public Result<User> findByOne(@PathVariable("id")String id){
        return Result.ok(userService.findByOne(id));
    }

    //post  /user  查询用户列表
    @RequestMapping(value = "findAll",method = RequestMethod.POST)
    @ApiOperation("查询所有用户")
    public Result<PageResult> findAll(@Validated @RequestBody UserQueryCondition userQueryCondition){
        PageResult userList=userService.findAll(userQueryCondition);
        return Result.ok(userList);
    }

    //post   /user  创建一个用户
    @RequestMapping(method = RequestMethod.POST)
    @ApiOperation(value = "创建一个用户")
    public Result<String> add(@RequestBody User user){
        return  Result.ok(userService.add(user));
    }

}
